﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using fanfu.Business;
using fanfu.Common;
using fanfu.Model;
using System.Data;

public partial class Photos : BasePage
{
    public StringBuilder photosHtml = new StringBuilder();
    public StringBuilder ReviewListHtml = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        //创建相册列表
        CreatePhotosHtml();

        //创建评论列表
        ReviewListHtml = new ReviewRule().CreateReviewListHtml((int)ReviewParentType.image, 20);
    }

    /// <summary>
    /// 创建相册列表
    /// </summary>
    private void CreatePhotosHtml()
    {
        //获取相册
        string sqlString = "SELECT * FROM Channel WHERE ParentId=3 AND Flag=" + (int)ChannelFlag.normal + " ORDER BY Ord";
        DataTable photos = SqlHelper.GetDataTable(sqlString);

        foreach (DataRow dr in photos.Rows)
        {
            //获取该相册的照片列表
            DataTable review = new UploadFileRule().GetPhotoListByParentId(dr["ID"].ToString());
            
            if (review.Rows.Count >= 1)
                photosHtml.AppendFormat("<li><a class=\"pic\" title=\"{0}\" href=\"PhotoAlone.aspx?current=2&group={1}&id={2}\"><img src=\"{3}\" /></a><p class=\"tag\">{4}</p><p class=\"num\">共{5}张</p></li>",
                dr["ChannelName"].ToString(), dr["ID"].ToString(), review.Rows[0]["ID"].ToString(), dr["LogoImg"].ToString().Replace("~/", ""), StringPlus.StringDot(dr["ChannelName"].ToString(), 18), review.Rows.Count);
            else
                photosHtml.AppendFormat("<li><a class=\"pic\" title=\"{0}\" href=\"PhotoAlone.aspx?current=2&group={1}&id=0\"><img src=\"{2}\" /></a><p class=\"tag\">{3}</p><p class=\"num\">共{4}张</p></li>",
                dr["ChannelName"].ToString(), dr["ID"].ToString(), dr["LogoImg"].ToString().Replace("~/", ""), StringPlus.StringDot(dr["ChannelName"].ToString(), 18), review.Rows.Count);
        }
    }
}